home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Documents / NeXTAnswers / appkit.829 < prev    next >
Text File  |  1992-02-06  |  5KB  |  207 lines

  1. {\rtf0\ansi{\fonttbl\f0\fnil Times-Roman;\f2\fmodern Courier;\f1\fswiss Helvetica;}
  2. \paperw12940
  3. \paperh12760
  4. \margl120
  5. \margr1000
  6. {\colortbl\red0\green0\blue0;}
  7. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\f0\b0\i0\ul0\fs28\fc0 bug workaround for 
  8. \b acceptColor
  9. \b0 :
  10. \b atPoint:
  11. \b0  in flipped views
  12. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600 \
  13. \
  14. Q:  
  15. \fc0 I  have a flipped view and I implement my own 
  16. \b acceptColor:atPoint:
  17. \b0  method to receive color.  If I drag a color to that view, my 
  18. \b acceptColor:atPoint
  19. \b0  method will 
  20. \i not
  21. \i0  be called, but if I drag the color to strategic locations 
  22. \i above
  23. \i0  my view, my
  24. \b  acceptColor:atPoint: 
  25. \b0 method 
  26. \i will
  27. \i0  be called.  Why?\
  28. \
  29. A:  This is a known bug in the AppKit.  This bug has been reported and it will be fixed in our next major software release.  For the time being, you can use the following bug workaround provided courtesy of Eric Ly and Glenn Reid from RightBrain Software.  This fix will work for flipped views as well as non-flipped views.\
  30. \
  31. You'll need to add the following 3 files to your IB.proj, an 
  32. \b ENXCP.psw
  33. \b0  file, and 
  34. \b ENXColorPanel.h
  35. \b0  and 
  36. \b ENXColorPanel.m
  37. \b0  files, that constitute a subclass of 
  38. NXColorPanel.  You also have to change your 
  39. \b _main
  40. \b0  file to use 
  41. \b poseAs: 
  42. \b0 which forces the AppKit to use the new subclass 
  43. ENXColorPanel instead of  
  44. NXColorPanel
  45. \i .\
  46.  
  47. \i0 \
  48. Note that you don't need to call 
  49. \b convertPoint:fromView:
  50. \b0  in your own 
  51. \b acceptColor:atPoint:
  52. \b0  method, since it's already done in the workaround code.\
  53. \
  54. Here's a possible implementation of 
  55. \b acceptColor:atPoint:
  56. \b0 \
  57.  
  58. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\f2\fs24\fc0 - acceptColor:(NXColor) c atPoint:(NXPoint *)p\
  59. \{\
  60.     someColor = c; /*someColor is an instance variable */\
  61.     [self display];\
  62.     return self;\
  63. \}\
  64.  
  65. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\i\fs28\fc0 \
  66.  
  67. \i0 File 
  68. \b myTest_main.m
  69. \b0 \
  70.  
  71. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\f2\fs24\fc0 #import <stdlib.h>\
  72. #import <appkit/Application.h>\
  73. #import "ENXColorPanel.h"\
  74. #import <objc/Object.h>\
  75. \
  76. void main(int argc, char *argv[]) \{\
  77.     NXApp = [Application new];\
  78.     
  79. \b [ENXColorPanel poseAs:[NXColorPanel class]]
  80. \b0 ;\
  81.     [NXApp loadNibSection:"acceptColor.nib" owner:NXApp];\
  82.     [NXApp run];\
  83.     [NXApp free];\
  84.     exit(0);\
  85. \}\
  86.  
  87. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\fs28\fc0 \
  88. File 
  89. \b ENXCP.psw
  90. \b0 \
  91.  
  92. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\f2\fs24\fc0 defineps PSWfindownedwindow(float x; float y;\
  93.     | float *xp; float *yp; unsigned int *window)\
  94.     x y Above 0 findwindow\
  95.     \{\
  96.         dup currentowner currentcontext eq\
  97.     \{\
  98.         window yp xp\
  99.     \}\{\
  100.         pop pop pop\
  101.         0 window\
  102.     \} ifelse\
  103.     \}\{\
  104.         pop pop pop\
  105.     0 window\
  106.     \} ifelse\
  107. endps\
  108. \
  109.  
  110. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\fs28\fc0 File 
  111. \b ENXColorPanel.h
  112. \b0 \
  113.  
  114. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\f2\fs24\fc0 #import <appkit/NXColorPanel.h>\
  115. \
  116. @interface ENXColorPanel:NXColorPanel\
  117. \{\
  118. \}\
  119. \
  120. + (BOOL)dragColor:(NXColor)color withEvent:(NXEvent *)theEvent     \
  121.     fromView:controlView;\
  122. \
  123. @end\
  124. \
  125.  
  126. \f0\fs28 File
  127. \b  ENXColorPanel.m
  128. \b0 \
  129.  
  130. \f2\fs24 #import "ENXColorPanel.h"\
  131. #import <appkit/Application.h>\
  132. #import <appkit/publicWraps.h>\
  133. #import <objc/List.h>\
  134. #import "ENXCP.h"\
  135. \
  136. @implementation ENXColorPanel\
  137. \
  138. /*\
  139.  * doHitTest: similar to hitTest: (View) but not quite.\
  140.  */\
  141. \
  142. static id doHitTest(id rootView, const NXPoint *aPoint)\
  143. \{\
  144.     id subviews, subview;\
  145.     int i;\
  146.     NXPoint point;\
  147.     NXRect rect;\
  148. \
  149.     point = *aPoint;\
  150.     [rootView convertPoint:&point fromView:nil];\
  151.     [rootView getBounds:&rect];\
  152.     if (NXMouseInRect(&point, &rect, [rootView isFlipped])) \{\
  153.     subviews = [rootView subviews];\
  154.     for (i = [subviews count] - 1; i >= 0; i--) \{\
  155.         subview = [subviews objectAt:i]; \
  156.         if ((subview = doHitTest(subview, aPoint)))\
  157.         return subview;\
  158.     \}\
  159.     return rootView;\
  160.     \} else\
  161.         return nil;\
  162. \}\
  163. \
  164. + (BOOL)dragColor:(NXColor)color withEvent:(NXEvent *)theEvent     \
  165.     fromView:controlView\
  166. \{\
  167.     id view, window;\
  168.     BOOL result;\
  169.     NXEvent *event;\
  170.     NXPoint point, hit;\
  171.     unsigned int hitWindow, wNum;\
  172.     \
  173.     result = [super dragColor:color withEvent:theEvent fromView:controlView];\
  174.    \
  175.     // Get the NX_WINMOVED event for the color swatch\
  176.     event = [NXApp peekAndGetNextEvent:NX_KITDEFINEDMASK];\
  177.     if (event) \{\
  178.         DPSPostEvent(event, 1);\
  179.     point = event->location;\
  180.     point.x += 6.0;        // Compute mouse location\
  181.     point.y += 6.0;\
  182.     PSWfindownedwindow(point.x, point.y, &hit.x, &hit.y, &hitWindow);\
  183.     if (hitWindow) \{\
  184.         NXConvertGlobalToWinNum(hitWindow, &wNum);\
  185.         window = [NXApp findWindow:wNum];\
  186.         view = doHitTest([window contentView], &hit);\
  187.         if ([view isFlipped]\
  188.             && [view respondsTo:@selector(acceptColor:atPoint:)]) \{\
  189.         [view convertPoint:&hit fromView:nil];\
  190.         [view acceptColor:color atPoint:&hit];\
  191.         \}\
  192.     \}\
  193.     \}\
  194.     return result;\
  195. \}\
  196. \
  197. @end\
  198.  
  199. \f0\fs28 \
  200.  
  201. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 QA829\
  202. \
  203. Not Valid for 1.0\
  204. Valid for 2.0\
  205. \
  206.  
  207.